package com.tensquare.search.service;

import com.tensquare.search.dao.ArticleSearchDao;
import com.tensquare.search.pojo.Article;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
import util.IdWorker;

/**
 * @author: WangYaWei
 * @description:
 * @create: 2019-08-16 17:07
 **/
@Service
public class ArticleSearchService {
    @Autowired
    private IdWorker idWorker;

    @Autowired
    private ArticleSearchDao articleSearchDao;

    public void add(Article article){
        article.setId(idWorker.nextId() + "");
        articleSearchDao.save(article);
    }

    public Page<Article> findByKeyword(String keyword, int page, int size) {
        return articleSearchDao.findByTitleLikeOrContentLike(keyword, keyword, PageRequest.of(page - 1, size));
    }
}
